﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DosciWordPlugin.Common
{
    public static class WinApp
    {
        public static DialogResult MsgBoxInfo(string msg, string title = "", Control owner = null)
        {
            string titleStr = string.IsNullOrEmpty(title) ? "提示信息" : title;
            if (owner == null)
                return MessageBox.Show(msg, titleStr, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
            else
                return MessageBox.Show(owner, msg, titleStr, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
        }
        public static DialogResult MsgBoxWarning(string msg, string title = "", Control owner = null)
        {
            string titleStr = string.IsNullOrEmpty(title) ? "警告信息" : title;
            if (owner == null)
                return System.Windows.Forms.MessageBox.Show(msg, title, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
            else
                return System.Windows.Forms.MessageBox.Show(owner, msg, title, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
        }

        public static DialogResult MsgBoxError(string msg, string title = "", Control owner = null)
        {
            string titleStr = string.IsNullOrEmpty(title) ? "错误信息" : title;
            if (owner == null)
                return System.Windows.Forms.MessageBox.Show(msg, titleStr, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            else
                return System.Windows.Forms.MessageBox.Show(owner, msg, titleStr, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
        }
        public static DialogResult MsgBoxOkCancel(string msg, string title = "", Control owner = null)
        {
            string titleStr = string.IsNullOrEmpty(title) ? "询问信息" : title;

            if (owner == null)
                return MessageBox.Show(msg, titleStr, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            else
                return MessageBox.Show(owner, msg, titleStr, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
        }

        public static DialogResult MsgBoxOkCancel(Control control, string msg, string title = "")
        {
            Func<DialogResult> showMsg = () => MsgBoxOkCancel(msg, title, control);
            return (DialogResult)control.Invoke(showMsg);
        }

        public static DialogResult MsgBoxWarning(Control control, string msg, string title = "")
        {
            Func<DialogResult> showMsg = () => MsgBoxWarning(msg, title, control);
            IAsyncResult ar = control.BeginInvoke(showMsg);
            object obj = control.EndInvoke(ar);
            return (DialogResult)obj;
        }

        public static DialogResult MsgBoxInfo(Control control, string msg, string titile = "")
        {
            Func<DialogResult> showMsg = () => MsgBoxInfo(msg, titile, control);
            return (DialogResult)control.Invoke(showMsg);
        }

        public static DialogResult MsgBoxError(Control control, string msg, string titile = "")
        {
            Func<DialogResult> showMsg = () => MsgBoxError(msg, titile, control);
            return (DialogResult)control.Invoke(showMsg);
        }
    }
}
